/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package samoloty.controler;

import Utils.FormatUtils;
import java.text.Format;
import samoloty.model.IDataModel;
import samoloty.model.models.PantryModel;
import samoloty.model.models.PaxWeightsModel;
import samoloty.view.MainWindow;
import samoloty.view.MyButton;
import samoloty.view.SiPanel;

/**
 *
 * @author borysfan
 */
public class SiPanelControler implements MyControler {

    private SiPanel panel;
    private Controler controler;
    private IDataModel dataModel;

    public SiPanelControler(Controler c) {
        controler = c;
        initPanel();
    }

    public SiPanelControler(Controler c, IDataModel model) {
        controler = c;
        dataModel = model;
        initPanel();
    }

    public void initPanel() {
        panel = new SiPanel();
    }

    public SiPanel getPanel() {
        return panel;
    }

    public void setDataModel(IDataModel model) {
        dataModel = model;
        initData();
    }

    private void initData() {
    }

    public void setUpWindow() {
        MainWindow window = controler.getView();
        window.setLeftPanelVisible(true);
        window.setRightPanelVisible(true);
        window.setAllBtnStyle(MyButton.ACTIVE_BUTTON);
        window.setSiBtnStyle(MyButton.CHOOSE_BUTTON);
        panel.firstFocused();
    }

    public void update() {
        PaxWeightsModel paxModel = controler.getPaxPanelControler().get_vpaxweights();
        panel.setPaxWeightValue("M" + paxModel.getM() + " F" + paxModel.getF() + " CH" + paxModel.getCh());

        //DEADLOADS IN HOLDS TTL: vttlholdsw / B: vttlholdb / C: vttlholdc / M: vttlholdm
        String deadLoadInHoldsTTL = new String();
        deadLoadInHoldsTTL += Math.round(controler.compute_vttlholdsw()) + "";
        long holdb = Math.round(controler.getHoldsPanelControler().get_vttlholdb());
        long holdc = Math.round(controler.getHoldsPanelControler().get_vttlholdc());
        long holdm = Math.round(controler.getHoldsPanelControler().get_vttlholdm());
        deadLoadInHoldsTTL += " / B: " + holdb + " / C: " + holdc + " / M: " + holdm;
        panel.setDeadLoadsValue(deadLoadInHoldsTTL);

        //ZFW LIMITS:   FWD:   +vlizfwfwd   AFT:   +vlizfwaft   NOW:   +vzfwi
        String zfwLimits = new String();
        double vlizfwfwd = controler.getInfoPanelControler().compute_vlizfwfwd();
        double vlizfwaft = controler.getInfoPanelControler().compute_vlizfwaft();
        double vzfwi = controler.getInfoPanelControler().compute_vzfwi();
        zfwLimits = "FWD:  +" + FormatUtils.getStringWithPrecision(vlizfwfwd, 2) + "   AFT:  +" + FormatUtils.getStringWithPrecision(vlizfwaft, 2) + "   NOW:  +" + FormatUtils.getStringWithPrecision(vzfwi, 2);
        panel.setZfwLimits(zfwLimits);

        //PANTRY:   FWD:   vpantryfwd   MID:   vpantrymid   AFT:   vpantryaft
        String pantry = new String();
        String vpantryfwd = controler.getDowPanelControler().get_vpantryfwd();
        String vpantrymid = controler.getDowPanelControler().get_vpantrymid();
        String vpantryaft = controler.getDowPanelControler().get_vpantryaft();
        //conditions
        PantryModel pantryModel = dataModel.getPantry();
        double aftIndex = pantryModel.getAftIndex();
        int aftMax = pantryModel.getAftMax();
        double fwdIndex = pantryModel.getFwdIndex();
        int fwdMax = pantryModel.getFwdMax();
        double midIndex = pantryModel.getMidIndex();
        double midMax = pantryModel.getMidMax();
        if (fwdIndex != 0 && fwdMax != 0) {
            pantry += "   FWD:   " + vpantryfwd;
        }
        if (midIndex != 0 && midMax != 0) {
            pantry += "   MID:   " + vpantrymid;
        }
        if (aftIndex != 0 && aftMax != 0) {
            pantry +=  "   AFT:   " + vpantryaft;
        }
        panel.setPantryValue(pantry);

    }

    public String getVsi1() {
        return panel.getVsi1();
    }

    public String getVsi2() {
        return panel.getVsi2();
    }

    public String getVsi3() {
        return panel.getVsi3();
    }

    public String getVsi4() {
        return panel.getVsi4();
    }

    public String getVsi5() {
        return panel.getVsi5();
    }

    public String getVsi6() {
        return panel.getVsi6();
    }

    public String getVsi7() {
        return panel.getVsi7();
    }

    public void firstFocused() {
        panel.firstFocused();
    }

    public void reset(){
        panel.reset();

    }
}
